import config from "./config"
// 封装一个api请求的函数
export default function request(url, data, method = "GET") {
  return new Promise((resolve, reject) => {
    wx.request({
      url:config.mobileHost +url,
      data,
      method,
      header:{
        // 每次请求都携带cookie
        cookie:wx.getStorageSync('cookie_key')&&wx.getStorageSync('cookie_key').join(';')
      },
      success:(res)=>{
        // 如果有data
        if(data && data.isLogin){
          wx.setStorageSync('cookie_key',res.cookies)
        }
        resolve(res.data)
      },
      fial:(err)=>{
        reject(err)
      }
    })
  })
}